/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Interface.Producao;


import Interface.Producao.Cortesias.CortesiasDao;
import Interface.Producao.Cortesias.JPCortesias;
import Interface.Producao.Descontos.DescontosDao;
import Interface.Producao.Descontos.JPDescontos;
import Interface.Producao.Gloss.JPGlos;
import Interface.Producao.Gloss.QueryGlos;
import Interface.Producao.Inco.JPInco;
import Interface.Producao.Inco.QueryInco;
import Interface.Producao.Particular.JPParticular;
import Interface.Producao.Particular.ParticularDao;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
import sft.Autenticacao.Sessao;
import sft.Autenticacao.perfil.logica.PerfilAcesso;
import sft.Principal.Principal;

/**
 *
 * @author Adriano
 */
public class JIProducao extends javax.swing.JInternalFrame {

    private static Principal t;
    public JIProducao(Principal p) {
        t = p;
        initComponents();
        iniciarComponetes();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        JTPainelAbas = new javax.swing.JTabbedPane();
        jPanel1 = new javax.swing.JPanel();
        jButton1 = new javax.swing.JButton();
        jTextField1 = new javax.swing.JTextField();
        jButton2 = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();

        setMinimumSize(new java.awt.Dimension(960, 34));
        setPreferredSize(new java.awt.Dimension(960, 600));

        jPanel1.setBackground(new java.awt.Color(255, 255, 255));
        jPanel1.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        jButton1.setText("Sair");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jTextField1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextField1ActionPerformed(evt);
            }
        });

        jButton2.setText("Pesquisa");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        jLabel1.setText("OS:");

        jLabel2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Help/img/LOGO.png"))); // NOI18N

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 74, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 364, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButton2)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 291, Short.MAX_VALUE)
                .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 70, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jButton1)
                            .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jButton2)
                            .addComponent(jLabel1)))
                    .addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(JTPainelAbas)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(JTPainelAbas, javax.swing.GroupLayout.PREFERRED_SIZE, 500, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(189, Short.MAX_VALUE))
        );

        getAccessibleContext().setAccessibleParent(this);

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        // TODO add your handling code here:
        if(t == null){
           t = new Principal(); 
        }
        t.ProdClose();
        dispose();
    }//GEN-LAST:event_jButton1ActionPerformed

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
        // TODO add your handling code here:
        pesquisar();
    }//GEN-LAST:event_jButton2ActionPerformed

    private void jTextField1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextField1ActionPerformed
        // TODO add your handling code here:
        jButton2.requestFocus();
    }//GEN-LAST:event_jTextField1ActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTabbedPane JTPainelAbas;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JPanel jPanel1;
    private static javax.swing.JTextField jTextField1;
    // End of variables declaration//GEN-END:variables
    
    //declarar variaveis
    private JPInco i;
    private JPGlos g;
    private JPParticular p;
    private JPCortesias c;
    private JPDescontos d;
    //finalizar declaração
    //iniciar Componentes
    
   
    private void iniciarComponetes() {
        Sessao.UpdateInstance();
        PerfilAcesso p1 = Sessao.getInstance().getUsuario().getPerfil();
        
        if(p1.isProd_inco()){
        if(i == null){
            i = new JPInco();
            JTPainelAbas.add("Inconsistencia",i);
            i.setVisible(true);
        }
        }
        if(p1.isProd_glos()){
        if(g == null){
            g = new JPGlos();
            JTPainelAbas.add("Glosa",g);
            g.setVisible(true);
        }
        }
        if(p1.isProd_part()){
        if(p == null){
            p = new JPParticular();
            JTPainelAbas.add("Particular",p);
            p.setVisible(true);
        }
        }
        if(p1.isProd_cort()){
        if(c == null){
            c = new JPCortesias();
            JTPainelAbas.add("Cortesias",c);
            c.setVisible(true);
        }
        }
        if(p1.isProd_desc()){
        if(d == null){
            d = new JPDescontos();
            JTPainelAbas.add("Descontos",d);
            d.setVisible(true);
        }
        }
        if(p1.isProd_desc()) JTPainelAbas.setSelectedComponent(d);
        if(p1.isProd_cort()) JTPainelAbas.setSelectedComponent(c);
        if(p1.isProd_part()) JTPainelAbas.setSelectedComponent(p);
        if(p1.isProd_glos()) JTPainelAbas.setSelectedComponent(g);
        if(p1.isProd_inco()) JTPainelAbas.setSelectedComponent(i);
    }
    //finalizar inicialização

    private void pesquisar() {
        //se for inconsistencia
       
        try {
            if (JTPainelAbas.getSelectedComponent() == i) {
                QueryInco q = new QueryInco();
                i.setList(q.getList(jTextField1.getText()));
            }
            //se for glosa
            if (JTPainelAbas.getSelectedComponent() == g) {
                QueryGlos q = new QueryGlos();
                g.setList(q.getList(jTextField1.getText()));
            }
            if(JTPainelAbas.getSelectedComponent() == p){
                ParticularDao dao = new ParticularDao();
                p.setList(dao.getParticular(jTextField1.getText()));
            }
            if(JTPainelAbas.getSelectedComponent() == c){
                CortesiasDao dao = new CortesiasDao();
                c.setList(dao.getCortesias(jTextField1.getText()));
            }
            if(JTPainelAbas.getSelectedComponent() == d){
                DescontosDao dao = new DescontosDao();;
                d.setList(dao.getDescontos(jTextField1.getText()));
            }
        } catch (SQLException ex) {
            Logger.getLogger(JIProducao.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    
    public static void limpaTexto(){
        jTextField1.setText("");
    }
}
